home *** CD-ROM | disk | FTP | other *** search
- /*
- cvabout.cpp
-
- Bouncing About Box
-
- C++/Views 2.0 Demo
- Copyright (c) 1992, by Liant Software Corp.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- */
-
- #include "cvabout.h"
- #include "cvbounce.h"
- #include "pushbttn.h"
- #include "port.h"
- #include "bitmap.h"
- #include "timer.h"
- #include "cvhow.h"
-
- BounceAbout::BounceAbout(VWindow *pwin) :
- bouncers(5),
- VDialog(92, 77, 150, 100, pwin, StyleTitle | StyleCloseBox)
- {
- setBackground(new VBrush(WHITE));
- setTitle("About");
-
- /* create About button */
- VPushButton *aboutbttn;
- aboutbttn = new VPushButton(VFrame(170, 120, 120, 30), this, StyleDefaultButton, "About");
- aboutbttn->uponClick(this, methodOf(BounceAbout, aboutBtn));
-
- /* create OK button */
- VPushButton *okbttn;
- okbttn = new VPushButton(VFrame(170, 160, 120, 30), this, StyleDefaultButton, "Ok");
- setDefButton(okbttn);
- okbttn->uponClick(this, methodOf(VDialog, ok));
-
- /* place Bouncer objects into collection */
- bouncers.add(new Bouncer("C++/Views", 10, 20));
- bouncers.add(new Bouncer("Demo Program v2.0", 10, 40));
- bouncers.add(new Bouncer("Copyright © 1992", 10, 60));
- bouncers.add(new Bouncer("by Liant Software Corp.", 10, 80));
-
- /* create an event timer */
- timer = new VTimer;
- timer->uponTimeout(this, methodOf(BounceAbout, startBouncing));
- timer->start(4000);
- }
-
- BounceAbout::~BounceAbout()
- {
- /* destroy background brush */
- delete getBackground();
-
- delete timer;
-
- bouncers.freeContents();
- }
-
- boolean BounceAbout::free()
- {
- delete this;
- return(TRUE);
- }
-
- boolean BounceAbout::paint()
- /*
- Paint the contents of the About box.
- */
- {
- VPort port(this);
- VPen pn(BLACK);
- VBitMap bmap("LIANT");
-
- port.open();
- port.usePen(&pn);
-
- port.drawBitMap(&bmap, 165, 20);
-
- int i, count;
- Bouncer *bnc;
-
- count = (int)bouncers.count();
- for (i = 0; i < count; i++) {
- bnc = (Bouncer *)bouncers.idAt(i);
- if (bnc) {
- pn.color((i % 2) ? RED : BLACK);
- port.wrtText(bnc->str, bnc->curX, bnc->curY);
- }
- }
-
- port.close();
- return (TRUE);
- }
-
- boolean BounceAbout::startBouncing()
- /*
- Called at the end of the initial timeout...
- */
- {
- /* change the timer call back */
- timer->uponTimeout(this, methodOf(BounceAbout, bounceThem));
- timer->start(50);
- return(TRUE);
- }
-
- boolean BounceAbout::bounceThem()
- /*
- Called by the timer, moves the bouncing objects
- */
- {
- VPort port(this);
- VPen pn;
-
- int x, y, w, h;
- getArea(&x, &y, &w, &h);
-
- port.open();
- port.usePen(&pn);
-
- int i, count;
- Bouncer *bnc;
-
- count = (int)bouncers.count();
- for (i = 0; i < count; i++) {
- bnc = (Bouncer *)bouncers.idAt(i);
- if (bnc) {
- /* erase old, old message */
- pn.color(WHITE);
- port.wrtText(bnc->str, bnc->curX, bnc->oldY2);
-
- /* erase old message */
- pn.color(LightGray);
- port.wrtText(bnc->str, bnc->curX, bnc->curY);
-
- bnc->oldY2 = bnc->oldY;
- bnc->oldY = bnc->curY;
- bnc->curY += bnc->yVel;
- bnc->yVel = (bnc->curY > (h - 10) && bnc->yVel > 0)
- ? -bnc->yVel : bnc->yVel + 1;
- }
- }
-
- /* now draw the real text (do last for maximum visibility */
- for (i = 0; i < count; i++) {
- bnc = (Bouncer *)bouncers.idAt(i);
- if (bnc) {
- /* draw message at new location */
- pn.color((i % 2) ? RED : BLACK);
- port.wrtText(bnc->str, bnc->curX, bnc->curY);
- }
- }
-
- port.close();
-
- return(TRUE);
- }
-
- boolean BounceAbout::aboutBtn(VButton *b)
- /*
- "About" button pressed
- */
- {
- /* Display a "How-does-it-work" dialog */
- HowView how(this, "About:About", "cvabout.cpp");
-
- /* make the about how visible */
- how.show();
-
- /* activate the dialog (as a modal dialog) */
- how.modal();
-
- return(TRUE);
- }
-
-